﻿using System;
using Glue;
using GlueTests.Builders;
using Xunit;

namespace GlueTests.MappingTests
{
    public class When_flattening_towards_left
    {
        private readonly Mapping<DomainPerson, GuiPerson> personMapping;

        public class GuiPerson
        {
            public String Name { get; set; }
            public GuiAddress Address { get; set; }
        }

        public class GuiAddress
        {
            public String City { get; set; }
        }

        public class DomainPerson
        {
            public String Name { get; set; }
            public String City { get; set; }
        }


        public When_flattening_towards_left()
        {
            personMapping = new Mapping<DomainPerson, GuiPerson>();
            var addressMapping = new Mapping<DomainPerson, GuiAddress>();
            personMapping.Flatten(gui => gui.Address, addressMapping);
        }

        [Fact]
        public void Should_accept_relation()
        {
            var relations = personMapping.Relations;
            Assert.True(relations.IsRelatedTowardsOnRightSide(new PropertyBuilder(typeof(GuiPerson), "Address").Build())); 
        }
    }
}